package study.spring.mvc.useservlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class MyWebApplicationInitializer implements WebApplicationInitializer {

  public void onStartup(ServletContext servletContext) throws ServletException {
    // Load Spring web application configuration
    AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(SpringMvcConfig.class);
    DispatcherServlet dispatcherServlet = new DispatcherServlet(webApplicationContext);
    ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", dispatcherServlet);
    servlet.addMapping("/");//添加上下文路径地址
    servlet.setLoadOnStartup(1);//最优先启动
    servlet.setAsyncSupported(true); //设置允许异步线程
  }
}
